home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / magazi~1 / 442 / dialogtt.lst < prev    next >
Encoding:
File List  |  1989-09-12  |  8.9 KB  |  257 lines

  1. ' PROGRAM: Dialog Box Tutorial
  2. DIM medrbtn&(3),denrbtn&(2)
  3. GOSUB my_menu
  4. GOSUB initialize
  5. GOSUB window_open
  6. GOSUB ld_resource
  7. ON MENU GOSUB respond_menu
  8. DO
  9.   ON MENU
  10. LOOP
  11. PROCEDURE respond_menu
  12.   ' Procedure to respond to menu items
  13.   hold$=strip$(MENU(0))
  14.   IF hold$="Dialog Tutorial"
  15.     ' code to handle Desk menu item here
  16.     txt$="Dialog Box Tutorial|By David Plotkin"
  17.     ALERT 1,txt$,1,"OK",a%
  18.   ENDIF
  19.   IF hold$="Add info"
  20.     ' code for Add info
  21.     GOSUB show_resource
  22.   ENDIF
  23.   IF hold$="Quit"
  24.     ' code for Quit
  25.     GOSUB pgm_end
  26.   ENDIF
  27.   MENU OFF
  28. RETURN
  29. PROCEDURE my_menu
  30.   ' Menu definition procedure
  31.   MENU KILL
  32.   RESTORE m_data
  33.   DIM strip$(150)
  34.   FOR i%=0 TO 150
  35.     READ strip$(i%)
  36.     EXIT IF strip$(i%)="***"
  37.   NEXT i%
  38.   strip$(i%)=""
  39.   strip$(i%+1)=""
  40.   m_data:
  41.   DATA Desk,"Dialog Tutorial"
  42.   DATA -------------------
  43.   DATA 1,2,3,4,5,6,""
  44.   DATA File,Add info,--------------,Quit
  45.   DATA ***
  46.   MENU strip$()
  47. RETURN
  48. PROCEDURE initialize
  49.   ' initializes variables
  50.   ' These variable statements were written out by the Resource
  51.   ' Construction Set by toggling the box to write GFA Output under OUTPUT
  52.   ' in the GLOBAL menu item.  For this to work, you must have provided
  53.   ' an name for each item in the dialog box while using RSC.
  54.   LET benefits&=0 !RSC_TREE
  55.   LET title&=1 !Dialog box title string
  56.   LET name&=2 !Editable text field for name
  57.   LET address&=3 !Editable text field for street address
  58.   LET city&=4 !Editable text field for city
  59.   LET state&=5 !Editable text field for state
  60.   LET zip&=6 !Editable text field for zipcode
  61.   LET box1&=7 !Box around the medical plans(groups radio buttons)
  62.   LET box2&=12 !Box around the dental plans(groups radio buttons)
  63.   LET mplana&=9 !Medical plan A radio button
  64.   LET mplanb&=10 !Medical plan B radio button
  65.   LET mplanc&=11 !Medical plan C radio button
  66.   LET dplana&=14 !Dental plan A radio button
  67.   LET dplanb&=15 !Dental plan B radio button
  68.   LET depno&=17 !Title string for number of dependents
  69.   LET depup&=18 !Button to increase number of dependents (touchexit)
  70.   LET depdown&=16 !Button to decrease number of dependents (touchexit)
  71.   LET depnbrsl&=26 !Button holding the number of dependents
  72.   LET impdown&=20 !Button to decrease importance slider
  73.   LET impup&=23 !Button to increase importance slider
  74.   LET imparent&=21 !Box containing the importance slider
  75.   LET impslide&=22 !The importance slider
  76.   LET ok&=24 !OK exit button
  77.   LET cancel&=25 !Cancel exit button
  78.   LET mplnttle&=8 !Title string for medical plan box
  79.   LET dplnttle&=13 !Title string for dental plan box
  80.   ' now load the medical and dental radio button values into their arrays
  81.   medrbtn&(1)=mplana&
  82.   medrbtn&(2)=mplanb&
  83.   medrbtn&(3)=mplanc&
  84.   denrbtn&(1)=dplana&
  85.   denrbtn&(2)=dplanb&
  86. RETURN
  87. PROCEDURE ld_resource
  88.   ' load the resource file
  89.   RESERVE FRE(0)-30000
  90.   IF RSRC_LOAD("BENEFITS.RSC")=0
  91.     ALERT 3,"Resource file not found",1," STOP ",a%
  92.     RESERVE FRE(0)+30000
  93.     EDIT
  94.   ENDIF !RSRC_LOAD("BENEFITS.RSC")=0
  95.   ~RSRC_GADDR(0,0,adr%) !get the address of the dialog box
  96.   ' initialize the operating width of the importance slider
  97.   width%=OB_W(adr%,imparent&)-OB_W(adr%,impslide&)
  98. RETURN
  99. PROCEDURE show_resource
  100.   ' put the dialog box on the screen
  101.   ~FORM_CENTER(adr%,x%,y%,w%,h%) !get the centered coordinates
  102.   GET x%,y%,x%+w%,y%+h%,hold$ !store the screen rectangle
  103.   ' clear the dialog box strings
  104.   CHAR{{OB_SPEC(adr%,name&)}}=""
  105.   CHAR{{OB_SPEC(adr%,city&)}}=""
  106.   CHAR{{OB_SPEC(adr%,address&)}}=""
  107.   CHAR{{OB_SPEC(adr%,state&)}}=""
  108.   CHAR{{OB_SPEC(adr%,zip&)}}=""
  109.   ' set the number of dependents to zero
  110.   depnum%=0
  111.   CHAR{OB_SPEC(adr%,depnbrsl&)}=STR$(depnum%)
  112.   ' set the importance factor to 50
  113.   import%=50
  114.   CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
  115.   ' and the position of the slider itself to 500 (halfway)
  116.   sliderpos%=500
  117.   newpos%=width%/1000*sliderpos%
  118.   OB_X(adr%,impslide&)=newpos%
  119.   dum%=FORM_DIAL(1,0,0,0,0,x%,y%,x%+w%,y%+h%)
  120.   ~OBJC_DRAW(adr%,0,6,x%,y%,w%,h%)  ! draw the box
  121.   REPEAT !loop til OK or CANCEL is pressed
  122.     exit_obj%=FORM_DO(adr%,0)
  123.     ' handle different exit objects here
  124.     IF exit_obj%=depup& !number of dependents goes up
  125.       INC depnum%  ! increase by one
  126.       IF depnum%>99 !make sure only two digits (otherwise,...crash!)
  127.         depnum%=99
  128.       ENDIF !depnum%>99
  129.       CHAR{OB_SPEC(adr%,depnbrsl&)}=STR$(depnum%)
  130.       ~OBJC_DRAW(adr%,depnbrsl&,6,x%,y%,w%,h%)
  131.     ENDIF  ! exit_obj%=depup&
  132.     IF exit_obj%=depdown& !number of dependents goes down
  133.       DEC depnum% !decrease by one
  134.       IF depnum%<0  !hmmm, not possible
  135.         depnum%=0  ! fix it
  136.       ENDIF !depnum%<0
  137.       CHAR{OB_SPEC(adr%,depnbrsl&)}=STR$(depnum%)
  138.       ~OBJC_DRAW(adr%,depnbrsl&,6,x%,y%,w%,h%)
  139.     ENDIF !exit_obj%=depdown&
  140.     IF exit_obj%=impslide& !clicked on the slider itself
  141.       ' exit dialog and allow user to drag slider to new position
  142.       sliderpos%=GRAF_SLIDEBOX(adr%,imparent&,impslide&,0)
  143.       newpos%=width%/1000*sliderpos%
  144.       OB_X(adr%,impslide&)=newpos%
  145.       ' Now set value in slider
  146.       import%=sliderpos%/10
  147.       CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
  148.       ' redraw the slider
  149.       ~OBJC_DRAW(adr%,imparent&,3,x%,y%,w%,h%)
  150.     ENDIF ! exit_obj%=impslide&
  151.     IF exit_obj%=impdown& ! clicked on the down button
  152.       SUB sliderpos%,10  ! subtract five
  153.       IF sliderpos%<0
  154.         sliderpos%=0
  155.       ENDIF !sliderpos%<0
  156.       newpos%=width%/1000*sliderpos%
  157.       OB_X(adr%,impslide&)=newpos%
  158.       ' Now set value in slider
  159.       import%=sliderpos%/10
  160.       CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
  161.       ' redraw the slider
  162.       ~OBJC_DRAW(adr%,imparent&,3,x%,y%,w%,h%)
  163.     ENDIF ! exit_obj%=impdown&
  164.     IF exit_obj%=impup& ! clicked on the up button
  165.       ADD sliderpos%,10  ! add five
  166.       IF sliderpos%>1000
  167.         sliderpos%=1000
  168.       ENDIF !sliderpos%>1000
  169.       newpos%=width%/1000*sliderpos%
  170.       OB_X(adr%,impslide&)=newpos%
  171.       ' Now set value in slider
  172.       import%=sliderpos%/10
  173.       CHAR{OB_SPEC(adr%,impslide&)}=STR$(import%)
  174.       ' redraw the slider
  175.       ~OBJC_DRAW(adr%,imparent&,3,x%,y%,w%,h%)
  176.     ENDIF ! exit_obj%=impdown&
  177.     IF exit_obj%=ok&
  178.       hndl_ok
  179.     ENDIF  ! exit_obj%=ok&
  180.     IF exit_obj%=cancel&
  181.       dum%=FORM_DIAL(2,0,0,0,0,x%,y%,x%+w%,y%+h%)
  182.       PUT x%,y%,hold$  ! restore the screen
  183.       ' change the exit object back to non-selected
  184.       ~OBJC_CHANGE(adr%,exit_obj%,0,x%,y%,w%,h%,0,0)
  185.     ENDIF !exit_obj%=cancel&
  186.   UNTIL (exit_obj%=ok& OR exit_obj%=cancel&)
  187. RETURN
  188. PROCEDURE pgm_end
  189.   ' clean up memory, get rid of the resource and end
  190.   ~RSRC_FREE()  !toss the resource
  191.   RESERVE FRE(0)+30000 !get the memory back
  192.   CLOSEW #1
  193.   EDIT !return to the editor
  194. RETURN
  195. PROCEDURE window_open
  196.   OPENW 1
  197.   FULLW 1
  198.   CLEARW 1
  199.   TITLEW #1,"STLOG Dialog Box Demo in GFA Basic"
  200. RETURN
  201. PROCEDURE hndl_ok
  202.   dum%=FORM_DIAL(2,0,0,0,0,x%,y%,x%+w%,y%+h%)
  203.   PUT x%,y%,hold$  ! restore the screen
  204.   ' change the exit object back to non-selected
  205.   ~OBJC_CHANGE(adr%,exit_obj%,0,x%,y%,w%,h%,0,0)
  206.   ' recover the editable text fields
  207.   nm$=CHAR{{OB_SPEC(adr%,name&)}}
  208.   city$=CHAR{{OB_SPEC(adr%,city&)}}
  209.   address$=CHAR{{OB_SPEC(adr%,address&)}}
  210.   state$=CHAR{{OB_SPEC(adr%,state&)}}
  211.   zip$=CHAR{{OB_SPEC(adr%,zip&)}}
  212.   CLEARW 1
  213.   PRINT AT(1,1);"Results of Dialog Box: "
  214.   PRINT
  215.   PRINT "Name: ";nm$
  216.   PRINT "Address: ";address$
  217.   PRINT "City: ";city$;" State: ";state$;" Zip: ";zip$
  218.   ' and the radio buttons
  219.   ' First the medical plan (3 buttons):
  220.   select&=0 ! none selected
  221.   FOR cnt&=1 TO 3
  222.     IF BTST(OB_STATE(adr%,medrbtn&(cnt&)),0) ! test bit 0 (selected)
  223.       select&=medrbtn&(cnt&)
  224.     ENDIF ! BTST(OB_STATE(adr%,medrbtn&(cnt&)),0)
  225.   NEXT cnt&
  226.   IF select&<>0 ! a radio button was selected
  227.     ' retrieve the text of the selected button
  228.     med$=CHAR{OB_SPEC(adr%,select&)}
  229.     PRINT "Medical Plan Selected: ";med$;" which is button ";select&-8
  230.     ' change the radio buttons back to non-selected
  231.     ~OBJC_CHANGE(adr%,select&,0,x%,y%,w%,h%,32,0)
  232.   ELSE
  233.     PRINT "No medical plan was selected!"
  234.   ENDIF !select&<>0
  235.   ' now the dental plan buttons
  236.   select&=0 ! none selected
  237.   FOR cnt&=1 TO 2 !only two dental plan buttons
  238.     IF BTST(OB_STATE(adr%,denrbtn&(cnt&)),0) ! test bit 0 (selected)
  239.       select&=denrbtn&(cnt&)
  240.     ENDIF ! BTST(OB_STATE(adr%,denrbtn&(cnt&)),0)
  241.   NEXT cnt&
  242.   IF select&<>0 ! a radio button was selected
  243.     ' retrieve the text of the selected button
  244.     den$=CHAR{OB_SPEC(adr%,select&)}
  245.     PRINT "Dental Plan Selected: ";den$;" which is button ";select&-13
  246.     ' change the radio buttons back to non-selected
  247.     ~OBJC_CHANGE(adr%,select&,0,x%,y%,w%,h%,32,0)
  248.   ELSE
  249.     PRINT "No dental plan was selected!"
  250.   ENDIF !select&<>0
  251.   ' get the number of dependents (read the button contents)
  252.   nmdep$=CHAR{OB_SPEC(adr%,depnbrsl&)}
  253.   PRINT "Number of dependents: ";nmdep$
  254.   import$=CHAR{OB_SPEC(adr%,impslide&)}
  255.   PRINT "Importance of plans: ";import$
  256. RETURN
  257.